﻿namespace Hidistro.UI.SaleSystem.Tags
{
    using Hidistro.Core;
    using Hidistro.Entities;
    using Hidistro.SaleSystem.Catalog;
    using System;
    using System.Data;
    using System.Runtime.CompilerServices;
    using System.Text;
    using System.Text.RegularExpressions;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Xml;

    public class js_BrandHeader : WebControl
    {

        private string CreateUrl(string paraName, string paraValue)
        {
            string rawUrl = this.Context.Request.RawUrl;
            if (string.IsNullOrEmpty(paraValue))
            {
                return rawUrl;
            }
            if (rawUrl.IndexOf("?") >= 0)
            {
                if (string.IsNullOrEmpty(this.Context.Request.QueryString["CategoryId"]))
                {
                    rawUrl += "&CategoryId=" + Globals.UrlEncode(paraValue);
                }
                else
                {
                    rawUrl = rawUrl.Replace("CategoryId=" + this.Context.Request.QueryString["CategoryId"], "CategoryId=" + Globals.UrlEncode(paraValue));
                }
                return rawUrl;
            }
            string str4 = rawUrl;
            return (str4 + "?" + paraName + "=" + Globals.UrlEncode(paraValue));
        }

        protected override void Render(HtmlTextWriter writer)
        {
            writer.Write(this.RendHtml());
        }

        public string RendHtml()
        {
            int brandId = 0;
            int categoryId = 0;
            int.TryParse((HttpContext.Current.Handler as System.Web.UI.Page).Request.QueryString["brandId"], out brandId);
            int.TryParse((HttpContext.Current.Handler as System.Web.UI.Page).Request.QueryString["CategoryId"], out categoryId);

            DataSet brandCategories = CategoryBrowser.GetBrand(brandId, 8);
            StringBuilder builder = new StringBuilder();
            builder.AppendFormat("<div class=\"top_three\"><div class=\"three_nav\"><ul>");
            builder.AppendFormat("<li class=\"xgcp\"><img src=\"http://image.juseshop.com/images/js-img41.png\">相关品牌</li>");
            builder.AppendFormat("<li class=\"xgqb\">");
            string str = "all";
            builder.AppendFormat("<a  href=\"www.xjuse.com\" >首页</a>");
            DataTable branddt = brandCategories.Tables[0];
            for (int i = 0; i < branddt.Rows.Count; i++)
            {
                str = string.Empty;
                if (brandId == ((int)branddt.Rows[i]["BrandId"]))
                {
                    str = str + "select";
                }
                builder.AppendFormat("<a class=\"{0}\" href=\"{1}\" >{2}</a>", str, Globals.GetSiteUrls().UrlData.FormatUrl("branddetails", branddt.Rows[i]["BrandId"]), branddt.Rows[i]["BrandName"]).AppendLine();
            }
            builder.AppendFormat("</li>");
            builder.AppendFormat("<li class=\"qbpp\"><a href=\"/brandall.aspx\">查看所有品牌</a></li>");
            builder.AppendFormat("</ul></div>");
            builder.AppendFormat(" <div class=\"three_nav\"><ul>");
            builder.AppendFormat("<li class=\"xgcp\"><img src=\"http://image.juseshop.com/images/js-img41.png\">相关分类</li><li class=\"xgqb\">");
            str = "all";
            builder.AppendFormat("<a class=\"{0}\" href=\"{1}\" >全部</a>", str, this.CreateUrl("CategoryId", "")).AppendLine();

            DataTable categorydt = brandCategories.Tables[1];
            for (int y = 0; y < categorydt.Rows.Count; y++)
            {
                str = string.Empty;
                if (categoryId == ((int)categorydt.Rows[y]["CategoryId"]))
                {
                    str = str + "select";
                }
                builder.AppendFormat("<a class=\"{0}\" href=\"{1}\" >{2}</a>", str, this.CreateUrl("CategoryId", categorydt.Rows[y]["CategoryId"].ToString()), categorydt.Rows[y]["Name"]).AppendLine();
            }
            builder.AppendFormat("</li></ul></div>");

            //<div class="three_nav">
            //   <ul>
            //   <li class="xgcp"><img src="images/xqtubiao1_07.png">相关品牌</li>
            //   <li class="xgqb"><a href="#">全部</a><a href="#">100元及以下</a><a href="#">101-200元</a><a href="#">201-300元 </a><a href="#">301-500元</a><a href="#">500元以上</a></li>

            //   </ul>
            //</div>

            // </div>");
            builder.AppendLine("");
            builder.AppendFormat("");
            builder.AppendFormat("");
            builder.AppendLine("");
            builder.AppendLine("");
            return builder.ToString();
        }
    }
}

